﻿using Rio.Manager.Application.ViewModel.Administration;
using Rio.Manager.Application.ViewModel.FolderTypeAdministration;
using Rio.Manager.Application.ViewModel.GeneralTabs;

#region Header

/*
  In App.xaml:
  <Application.Resources>
      <vm:ViewModelLocatorTemplate xmlns:vm="clr-namespace:Rio.Manager.Application.ViewModel"
                                   x:Key="Locator" />
  </Application.Resources>

  In the View:
  DataContext="{Binding Source={StaticResource Locator}, Path=ViewModelName}"

  OR (WPF only):

  xmlns:vm="clr-namespace:Rio.Manager.Application.ViewModel"
  DataContext="{Binding Source={x:Static vm:ViewModelLocatorTemplate.ViewModelNameStatic}}"
*/

#endregion Header

namespace Rio.Manager.Application.ViewModel.Locator
{
    public class ViewModelLocator
    {
        #region Fields

        private static AdministrationTabViewModel _administrationTab;
        private static DashboardTabViewModel _dashboardTab;
        private static FolderTypeAdministrationTabViewModel _folderTypeAdministrationTab;
        private static GeneralParametersTabViewModel _generalParametersTab;
        private static ListUndoCheckOutTabViewModel _listUndoCheckOutTab;
        private static MainViewModel _main;
        private static ManageWorkflowModelTabViewModel _manageWorkflowModelTab;
        private static ManageWorkflowTabViewModel _manageWorkflowTab;
        private static NewWorkflowTabViewModel _newWorkflowTab;
        private static VersioningModelTabViewModel _versioningModelTab;
        private static ConnectorTabViewModel _connectorTab;
        private static ConnectorAddTabViewModel _connectorAddTab;
        private static BarCodeTabViewModel _BarCodeTab;
        private static BarCodeAddTabViewModel _BarCodeAddTab;
        private static GroupAssociationTabViewModel _GroupAssociationTab;
        private static GroupSynchronizationTabViewModel _GroupSynchronizationTab;

        #endregion Fields

        #region Constructors

        public ViewModelLocator()
        {
            CreateMain();
            CreateAdministrationTab();
            CreateDashboardTab();
            CreateFolderTypeAdministrationTab();
            CreateConnectorTab();
            CreateConnectorAddTab();
            //CreateCustomerTab();
            //CreateListUndoCheckOutTab();
            //CreateVersioningModelTab();
            //CreateGeneralParametersTab();
            //CreateNewWorkflowTab();
            //CreateManageWorkflowTab();
        }

        #endregion Constructors

        #region Properties

        //public static CustomerTabViewModel CustomerTabStatic
        //{
        //    get
        //    {
        //        if (_customerTab == null)
        //            CreateCustomerTab();

        //        return _customerTab;
        //    }
        //}

        public static AdministrationTabViewModel AdministrationTabStatic
        {
            get
            {
                if (_administrationTab == null)
                {
                    CreateAdministrationTab();
                }

                return _administrationTab;
            }
        }

        public static DashboardTabViewModel DashboardTabStatic
        {
            get
            {
                if (_dashboardTab == null)
                {
                    CreateDashboardTab();
                }

                return _dashboardTab;
            }
        }

        public static FolderTypeAdministrationTabViewModel FolderTypeAdministrationTabStatic
        {
            get
            {
                if (_folderTypeAdministrationTab == null)
                {
                    CreateFolderTypeAdministrationTab();
                }

                return _folderTypeAdministrationTab;
            }
        }

        public static GeneralParametersTabViewModel GeneralParametersTabStatic
        {
            get
            {
                if (_generalParametersTab == null)
                {
                    CreateGeneralParametersTab();
                }

                return _generalParametersTab;
            }
        }

        public static ListUndoCheckOutTabViewModel ListUndoCheckOutTabStatic
        {
            get
            {
                if (_listUndoCheckOutTab == null)
                {
                    CreateListUndoCheckOutTab();
                }

                return _listUndoCheckOutTab;
            }
        }

        public static MainViewModel MainStatic
        {
            get
            {
                if (_main == null)
                {
                    CreateMain();
                }

                return _main;
            }
        }

        public static ManageWorkflowModelTabViewModel ManageWorkflowModelTabViewModelStatic
        {
            get
            {
                if (_manageWorkflowModelTab == null)
                {
                    CreateManageWorkflowModelTab();
                }

                return _manageWorkflowModelTab;
            }
        }

        public static ManageWorkflowTabViewModel ManageWorkflowTabViewModelStatic
        {
            get
            {
                if (_manageWorkflowTab == null)
                {
                    CreateManageWorkflowTab();
                }

                return _manageWorkflowTab;
            }
        }

        public static NewWorkflowTabViewModel NewWorkflowTabViewModelStatic
        {
            get
            {
                if (_newWorkflowTab == null)
                {
                    CreateNewWorkflowTab();
                }

                return _newWorkflowTab;
            }
        }

        public static NewWorkflowTabViewModel NewChildflowTabViewModelStatic
        {
            get
            {
                if (_newWorkflowTab == null)
                {
                    CreateChildWorkflowTab();
                }

                return _newWorkflowTab;
            }
        }

        public static VersioningModelTabViewModel VersioningModelTabStatic
        {
            get
            {
                if (_versioningModelTab == null)
                {
                    CreateVersioningModelTab();
                }

                return _versioningModelTab;
            }
        }

        public static ConnectorTabViewModel ConnectorTabStatic
        {
            get
            {
                if (_connectorTab == null)
                {
                    CreateConnectorTab();
                }

                return _connectorTab;
            }
        }

        public static ConnectorAddTabViewModel ConnectorAddTabStatic
        {
            get
            {
                if (_connectorAddTab == null)
                {
                    CreateConnectorAddTab();
                }

                return _connectorAddTab;
            }
        }

        public static BarCodeTabViewModel BarCodeTabStatic
        {
            get
            {
                if (_BarCodeTab == null)
                {
                    CreateBarCodeTab();
                }

                return _BarCodeTab;
            }
        }

        public static BarCodeAddTabViewModel BarCodeAddTabStatic
        {
            get
            {
                if (_BarCodeAddTab == null)
                {
                    CreateBarCodeAddTab();
                }

                return _BarCodeAddTab;
            }
        }

        public static GroupAssociationTabViewModel GroupAssociationTabStatic
        {
            get
            {
                if (_GroupAssociationTab == null)
                {
                    CreateGroupAssociationTab();
                }

                return _GroupAssociationTab;
            }
        }

        public static GroupSynchronizationTabViewModel GroupSynchronizationTabStatic
        {
            get
            {
                if (_GroupSynchronizationTab == null)
                {
                    CreateGroupSynchronizationTab();
                }

                return _GroupSynchronizationTab;
            }
        }

        //[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
        //    "CA1822:MarkMembersAsStatic",
        //    Justification = "This non-static member is needed for data binding purposes.")]
        //public CustomerTabViewModel CustomerTab
        //{
        //    get
        //    {
        //        return CustomerTabStatic;
        //    }
        //}

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public AdministrationTabViewModel AdministrationTab
        {
            get
            {
                return AdministrationTabStatic;
            }
        }

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public DashboardTabViewModel DashboardTab
        {
            get
            {
                return DashboardTabStatic;
            }
        }

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public FolderTypeAdministrationTabViewModel FolderTypeAdministrationTab
        {
            get
            {
                return FolderTypeAdministrationTabStatic;
            }
        }

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public GeneralParametersTabViewModel GeneralParametersTab
        {
            get
            {
                return GeneralParametersTabStatic;
            }
        }

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public ListUndoCheckOutTabViewModel ListUndoCheckOutTab
        {
            get
            {
                return ListUndoCheckOutTabStatic;
            }
        }

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public MainViewModel Main
        {
            get
            {
                return MainStatic;
            }
        }

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public ManageWorkflowModelTabViewModel ManageWorkflowModelTab
        {
            get
            {
                return ManageWorkflowModelTabViewModelStatic;
            }
        }

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public ManageWorkflowTabViewModel ManageWorkflowTab
        {
            get
            {
                return ManageWorkflowTabViewModelStatic;
            }
        }

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public NewWorkflowTabViewModel NewWorkflowTab
        {
            get
            {
                return NewWorkflowTabViewModelStatic;
            }
        }

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public VersioningModelTabViewModel VersioningModelTab
        {
            get
            {
                return VersioningModelTabStatic;
            }
        }

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
    "CA1822:MarkMembersAsStatic",
    Justification = "This non-static member is needed for data binding purposes.")]
        public ConnectorTabViewModel ConnectorTab
        {
            get
            {
                return ConnectorTabStatic;
            }
        }

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public ConnectorAddTabViewModel ConnectorAddTab
        {
            get
            {
                return ConnectorAddTabStatic;
            }
        }

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
    "CA1822:MarkMembersAsStatic",
    Justification = "This non-static member is needed for data binding purposes.")]
        public BarCodeTabViewModel BarCodeTab
        {
            get
            {
                return BarCodeTabStatic;
            }
        }

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public BarCodeAddTabViewModel BarCodeAddTab
        {
            get
            {
                return BarCodeAddTabStatic;
            }
        }

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
"CA1822:MarkMembersAsStatic",
Justification = "This non-static member is needed for data binding purposes.")]
        public GroupAssociationTabViewModel GroupAssociationTab
        {
            get
            {
                return GroupAssociationTabStatic;
            }
        }

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public GroupSynchronizationTabViewModel GroupSynchronizationTab
        {
            get
            {
                return GroupSynchronizationTabStatic;
            }
        }

        #endregion Properties

        #region Methods

        /*
         * Clean Methods
         */
        public static void Cleanup()
        {
            ClearMain();
        }

        public static void ClearAdministrationTab()
        {
            _administrationTab.Cleanup();
            _administrationTab = null;
        }

        public static void ClearDashboardTab()
        {
            _dashboardTab.Cleanup();
            _dashboardTab = null;
        }

        public static void ClearFolderTypeAdministrationTab()
        {
            _folderTypeAdministrationTab.Cleanup();
            _folderTypeAdministrationTab = null;
        }

        public static void ClearGeneralParametersTab()
        {
            _generalParametersTab.Cleanup();
            _generalParametersTab = null;
        }

        public static void ClearListUndoCheckOutTab()
        {
            _listUndoCheckOutTab.Cleanup();
            _listUndoCheckOutTab = null;
        }

        public static void ClearMain()
        {
            _main.Cleanup();
            _main = null;
        }

        public static void ClearManageWorkflowModelTab()
        {
            _manageWorkflowModelTab.Cleanup();
            _manageWorkflowModelTab = null;
        }

        public static void ClearManageWorkflowTab()
        {
            _manageWorkflowTab.Cleanup();
            _manageWorkflowTab = null;
        }

        public static void ClearNewWorkflowTab()
        {
            _newWorkflowTab.Cleanup();
            _newWorkflowTab = null;
        }

        public static void ClearVersioningModelTab()
        {
            _versioningModelTab.Cleanup();
            _versioningModelTab = null;
        }

        public static void ClearConnectorTab()
        {
            _connectorTab.Cleanup();
            _connectorTab = null;
        }

        public static void ClearConnectorAddTab()
        {
            _connectorAddTab.Cleanup();
            _connectorAddTab = null;
        }

        public static void ClearBarCodeTab()
        {
            _BarCodeTab.Cleanup();
            _BarCodeTab = null;
        }

        public static void ClearBarCodeAddTab()
        {
            _BarCodeAddTab.Cleanup();
            _BarCodeAddTab = null;
        }

        public static void ClearGroupAssociationTab()
        {
            _GroupAssociationTab.Cleanup();
            _GroupAssociationTab = null;
        }

        public static void ClearGroupSynchronizationTab()
        {
            _GroupSynchronizationTab.Cleanup();
            _GroupSynchronizationTab = null;
        }

        /*
         * Create Methods
         */
        public static void CreateAdministrationTab()
        {
            if (_administrationTab == null)
            {
                _administrationTab = new AdministrationTabViewModel();
            }
        }

        public static void CreateDashboardTab()
        {
            if (_dashboardTab == null)
            {
                _dashboardTab = new DashboardTabViewModel();
            }
        }

        public static void CreateFolderTypeAdministrationTab()
        {
            if (_folderTypeAdministrationTab == null)
            {
                _folderTypeAdministrationTab = new FolderTypeAdministrationTabViewModel();
            }
        }

        public static void CreateGeneralParametersTab()
        {
            if (_generalParametersTab == null)
            {
                _generalParametersTab = new GeneralParametersTabViewModel();
            }
        }

        public static void CreateListUndoCheckOutTab()
        {
            if (_listUndoCheckOutTab == null)
            {
                _listUndoCheckOutTab = new ListUndoCheckOutTabViewModel();
            }
        }

        public static void CreateMain()
        {
            if (_main == null)
            {
                _main = new MainViewModel();
            }
        }

        public static void CreateManageWorkflowModelTab()
        {
            if (_manageWorkflowModelTab == null)
            {
                _manageWorkflowModelTab = new ManageWorkflowModelTabViewModel();
            }
        }

        public static void CreateManageWorkflowTab()
        {
            if (_manageWorkflowTab == null)
            {
                _manageWorkflowTab = new ManageWorkflowTabViewModel();
            }
        }

        public static void CreateNewWorkflowTab()
        {
            if (_newWorkflowTab == null)
            {
                _newWorkflowTab = new NewWorkflowTabViewModel();
            }
        }

        public static void CreateChildWorkflowTab()
        {
            if (_newWorkflowTab == null)
            {
                _newWorkflowTab = new NewWorkflowTabViewModel(true);
            }
        }

        public static void CreateVersioningModelTab()
        {
            if (_versioningModelTab == null)
            {
                _versioningModelTab = new VersioningModelTabViewModel();
            }
        }

        public static void CreateConnectorTab()
        {
            if (_connectorTab == null)
            {
                _connectorTab = new ConnectorTabViewModel();
            }
        }

        public static void CreateConnectorAddTab()
        {
            if (_connectorAddTab == null)
            {
                _connectorAddTab = new ConnectorAddTabViewModel();
            }
        }

        public static void CreateBarCodeTab()
        {
            if (_BarCodeTab == null)
            {
                _BarCodeTab = new BarCodeTabViewModel();
            }
        }

        public static void CreateBarCodeAddTab()
        {
            if (_BarCodeAddTab == null)
            {
                _BarCodeAddTab = new BarCodeAddTabViewModel();
            }
        }

        public static void CreateGroupAssociationTab()
        {
            if (_GroupAssociationTab == null)
            {
                _GroupAssociationTab = new GroupAssociationTabViewModel();
            }
        }

        public static void CreateGroupSynchronizationTab()
        {
            if (_GroupSynchronizationTab == null)
            {
                _GroupSynchronizationTab = new GroupSynchronizationTabViewModel();
            }
        }

        //public static void CreateCustomerTab()
        //{
        //    if (_customerTab == null)
        //    {
        //        _customerTab = new CustomerTabViewModel();
        //    }
        //}

        #endregion Methods
    }
}